<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-list-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">账目日期：</label>
				<div class="col-sm-8">
					<input id="accountDate" name="accountDate" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">物品名称：</label>
				<div class="col-sm-8">
					<input id="accountName" name="accountName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">数量：</label>
				<div class="col-sm-8">
					<input id="accountNumber" name="accountNumber" class="form-control" type="text" onkeyup="countMoney()">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单价：</label>
				<div class="col-sm-8">
					<input id="accountPrice" name="accountPrice" class="form-control" type="text" onkeyup="countMoney()">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">金额：</label>
				<div class="col-sm-8">
					<input id="accountMoney" name="accountMoney" class="form-control" type="text" readonly="readonly">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单位：</label>
				<div class="col-sm-8">
					<select id="accountUnit" name="accountUnit" class="form-control m-b" th:with="type=${@dict.getType('unit_list')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<!-- <div class="form-group">	
				<label class="col-sm-3 control-label">更新时间：</label>
				<div class="col-sm-8">
					<input id="updateTime" name="updateTime" class="form-control" type="text">
				</div>
			</div> -->
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
    
    	layui.use('laydate', function(){
			var laydate = layui.laydate;
			//执行一个laydate实例
			laydate.render({
				elem: '#accountDate' //指定元素
			});
		});
    
    
		var prefix = ctx + "account"
		$("#form-list-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			submitHandler: function(form) {
				/*$.operate.save(prefix + "/add", $('#form-list-add').serialize());*/
				add();
			}
		});
		
		Date.prototype.Format = function (fmt) { 
        var o = {
            "M+": this.getMonth() + 1, //月份 
            "d+": this.getDate(), //日 
            "h+": this.getHours(), //小时 
            "m+": this.getMinutes(), //分 
            "s+": this.getSeconds(), //秒 
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
            "S": this.getMilliseconds() //毫秒 
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        	return fmt;
    	} 
		
		function add() {
        	var accountDate = $("input[name='accountDate']").val();
        	accountDate = new Date(accountDate).Format("yyyy-MM-dd hh:mm:ss");
        	var accountName = $("input[name='accountName']").val();
        	var accountNumber = $("input[name='accountNumber']").val();
        	var accountPrice = $("input[name='accountPrice']").val();
        	var accountMoney = $("input[name='accountMoney']").val();
        	var accountUnit = $.form.selectSelects("accountUnit");
        	var accountInfo = $("input[name='remark']").val();
        	var createBy = $("input[name='createBy']").val();
        	var createTime =  $("input[name='createTime']").val();
        	var remark =  $("input[name='remark']").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "account/add",
        		data : {
        			"accountDate": accountDate,
        			"accountName": accountName,
        			"accountNumber" : accountNumber,
        			"accountPrice" : accountPrice,
        			"accountMoney" : accountMoney,
        			"accountUnit" : accountUnit,
        			"accountInfo" : accountInfo,
        			"createBy" : createBy,
        			"createTime" : createTime,
        			"remark":remark
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
        
        function countMoney(){
        	var accountNumber = $("input[name='accountNumber']").val();
        	var accountPrice = $("input[name='accountPrice']").val();
        	var accountMoneyInput =  document.getElementById("accountMoney");
        	accountMoneyInput.value = accountNumber*accountPrice;
        	
        }
        
		// h新建进入此页聚焦于第一输入框
		document.getElementsByName("accountDate")[0].focus()
		
	</script>
</body>
</html>
